﻿using System;
using System.IO;
using System.Web;
using ASPNETVN.PORTAL.Components.UI;

namespace ASPNETVN.PORTAL.Modules.PORTALSETTING.Controls
{
    public partial class EditCss : AddEditItemControl
    {
        protected override void OnInit(EventArgs e)
        {
            this.ButtonUpdate = btnUpdate;
            this.ButtonCancel = btnCancel;

            this.Update += AddEditItem_Update;
            base.OnInit(e);
        }

        void AddEditItem_Update(object sender, EventArgs e)
        {
            string virtualPath = string.Format("~/App_Themes/{0}/{0}.css", Request.QueryString["theme"]);
            string physicalPath = Server.MapPath(virtualPath);
            StreamWriter writer = new StreamWriter(physicalPath);
            writer.Write(TextBoxCssContent.Text);
            writer.Close();
            // Refresh.
            Response.Redirect(Request.RawUrl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                string virtualPath = string.Format("~/App_Themes/{0}/{0}.css", Request.QueryString["theme"]);
                string physicalPath = Server.MapPath(virtualPath);
                StreamReader reader = new StreamReader(physicalPath);
                TextBoxCssContent.Text = reader.ReadToEnd();
                reader.Close();
            }
        }
    }
}